package edu.xhu.kafkaproducer.test;

import edu.xhu.kafkaproducer.enums.KafkaTopic;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Random;

@SpringBootTest
@RunWith(SpringRunner.class)
public class HelloKafka {
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @Test
    public void helloKafka() {
        Random random = new Random();

        for (int i = 0; i < 1000; i++)
//            kafkaTemplate.send(CheckTopic.BILL_TEST_TOPIC, i % 3, "kafka-key", "hello kafka");
            kafkaTemplate.send(KafkaTopic.BILL_TEST_TOPIC, "hello kafka");
    }

    //包装类对象的缓存问题
    @Test
    public void test5() {
        Integer i1 = 10;
        Integer i2 = 10;
        System.out.println(i1 == i2);

        Integer i3 = 128;
        Integer i4 = 128;
        System.out.println(i3 == i4);

        Boolean b1 = true;
        Boolean b2 = true;
        System.out.println(b1 == b2);
    }

    @Test
    public void test6() {
        String str = new String("hello") + new String("world");
        String str1 = "helloworld";
        System.out.println(str == str1);

    }
}
